package com.example.shell.service.impl;

import cn.hutool.core.util.StrUtil;
import com.example.shell.client.OaClient;
import com.example.shell.config.FileConfig;
import com.example.shell.model.entity.AttendanceRecord;
import com.example.shell.model.entity.CheckinListRequest;
import com.example.shell.model.entity.UserInfo;
import com.example.shell.model.query.CheckinListQuery;
import com.example.shell.service.OaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Collections;
import java.util.List;

@Service
public class OaServiceImpl implements OaService {
    FileConfig fileConfig = new FileConfig();

    @Autowired
    private OaClient oaClient;

    @Override
    public UserInfo login(String username, String password) {
        UserInfo login;
        login = oaClient.login(username, password);
        return login;
    }

    @Override
    public List<AttendanceRecord> checkinList(CheckinListQuery query) {
        CheckinListRequest request = new CheckinListRequest();

        String token = fileConfig.get("LoginIdentity");
        if (StrUtil.isBlank(token)){
            return Collections.emptyList();
        }

        String limit = String.valueOf(query.getSize());
        String sEmployeeCode = query.getEmployeeCode();

        request.setStartDate(query.getStartDate());
        request.setEndDate(query.getEndDate());
        request.setToken(token);
        request.setLimit(limit);
        request.setSEmployeeCode(sEmployeeCode);


        List<AttendanceRecord> list = oaClient.checkinList(request);
        return list;
    }
}
